﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;
using KPIS.DBM;

namespace KPIS.GERP.GHRMS.BLL
{
    public class PositionTypeBLL : IPositionTypeBLL
    {
        IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);
        private static readonly IPositionTypeDAL DAL = DataAccess.CreatePositionTypes();

        private EmployeeTypeInfo emptypeInfo = new EmployeeTypeInfo();
        public IList<PositionTypeInfo> ListPositionTypes(Nullable<int> EmployeeTypes)
        {
            return DAL.ListPositionTypes(null, EmployeeTypes);
        }
        public IList<PositionTypeInfo> ListPositionTypes(Nullable<int> Sequence, Nullable<int> EmployeeTypes)
        {
            return DAL.ListPositionTypes(Sequence, EmployeeTypes);
        }

        public DataSet ListPosionTypeClass(int emp_type_seq)
        {
            dbManager.CreateParameters(2);
            dbManager.AddParameters(0, "@emp_type_seq", emp_type_seq);
            dbManager.AddParameters(1, "@RecordStatus", SystemInfo._ActiveRecordStatus);

            DataSet ds = new DataSet();
            dbManager.Open();
            ds = dbManager.ExecuteDataSet(CommandType.Text, "SELECT * from hrm_mp_position_types as pt, hrm_mp_classes as mc where pt.pos_type_seq = mc.pos_type_seq and pt.record_status=@RecordStatus and mc.record_status=@RecordStatus");
            dbManager.Dispose();
            //return DAL.ListInquire(new InquireInfo(0));
            return ds;
        }
        public DataSet LoadPositionTypes(Nullable<int> Sequence, Nullable<int> EmployeeTypes)
        {
            return DAL.LoadPositionTypes(Sequence, EmployeeTypes);
        }
        public void Insert(string Name, string NameShort, string NameEng, string NameEngShort
            , int EmployeeTypes, string Remarks, int CreatedBy)
        {
            try
            {
                emptypeInfo.Sequence = EmployeeTypes;

                DAL.Insert(new PositionTypeInfo(0, Name, NameShort, NameEng, NameEngShort, emptypeInfo, Remarks, CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string Name, string NameShort, string NameEng, string NameEngShort
            , int EmployeeTypes, string Remarks, int UpdatedBy)
        {
            try
            {
                emptypeInfo.Sequence = EmployeeTypes;

                DAL.Update(new PositionTypeInfo(Sequence, Name, NameShort, NameEng, NameEngShort, emptypeInfo, Remarks, 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                DAL.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }

                
    }
}
